<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------

namespace Home\Model;
use Think\Model;

/**
 * 平台基础信息模型
 */
class PtdataModel extends Model{

    /**
     * 获取奖励制度
     * @return array
     */
    public static function getJiangLiZhiDu(){
        //300|0.2,1000|0.3,2000|0.4,3000|0.5
        $zhidu = M('ptdata')->where(['id' => 1])->getField('zhidu');

        $a = explode(',',$zhidu);
        $data = [];
        foreach ($a as $k => $v){
            $b = explode('|',$v);

            $data[$b[0]] = $b[1];
        }
        return $data;
    }

    public static function getFenRunZhiDu(){
        //50|0.05,500|&
        $fenrun = M('ptdata')->where(['id' => 1])->getField('fenrun');
        $a = explode(',',$fenrun);
        $data = [];
        foreach ($a as $k => $v){
            $b = explode('|',$v);

            $data[$b[0]] = $b[1];
        }
        return $data;

    }

    /**
     * @param string $type  类型：hbtd=花呗通道，fkhbtd=风控花呗，xyktd=信用卡通道
     */
    public static function getTdRate($type){
        //10-199|0.2,200-399|0.5,400-599|1.2,600-4999|1.8
        $ptdata = M('ptdata')->find(1);
        $value = $ptdata[$type];
        $array = explode(',',$value);
        $arr = [];
        foreach ($array as $k => $v){
            $val = explode('|',$v);
            $arr[$k]['round'] = $val[0];
            $arr[$k]['rate'] = $val[1];
        }
        return $arr;
    }

    /**
     * 获取用户通道费率
     * @param string $type 类型：hbtd=花呗通道，fkhbtd=风控花呗，xyktd=信用卡通道,dmxyktd=当面信用卡通道
     * @param int $uid 用户id
     * @param int $money 金额
     */
    public static function getUserTdRate($type,$uid,$money){

        $gather = M('gather')->where(['uid' => $uid])->find();

        $ptdata = M('ptdata')->find(1);
        $value = $ptdata[$type];
        $array = explode(',',$value);
        $arr = [];
        foreach ($array as $k => $v){
            $val = explode('|',$v);
//            $rate = ($val[1]*100 + $selfRate*100)/100;
            $rate = $val[1];
            $arr[$k]['round'] = $val[0];
            $arr[$k]['rate'] = $rate;
            $round = explode('-',$val[0]);

            $arr[$k]['min'] = $round[0];
            $arr[$k]['max'] = $round[1];

            if(($money*100 - intval($round[0])*100 >= 0) && ($money*100 - intval($round[1])*100 < 0)){

                 $return = $rate;
            }else{

                continue;
            }
        }
        return $return;
    }

    /**
     * @param int $type 类型：1=手机网站支付,2=当面付,4=手机网站支付花呗,5=当面付信用卡
     */
    public static function getFkdByType($type){
        if($type == 1){
            $key = "xykfkd";
        }elseif($type == 2){
            $key = "hbfkd";
        }elseif($type == 4){
            $key = "waphbfkd";
        }elseif($type == 5){
            $key = "dmxykfkd";
        }

        $data = M('ptdata')->find(1);

        return $data[$key];
    }


}